package cm.emp.dao;

import cm.emp.bean.Person;
import cm.emp.util.ConnectionFactory;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Description:
 * Date: 2024/6/14
 * User: 21719
 */
public class UserLoginDaoImpl implements UserLoginDao{
    @Override
    public Person getLogin(Person person) {
        String sql = "select * from person where userAccount='"+person.getUserAccount()+"' and userPassword='"+person.getUserPassword()+"'";
        Connection connection = ConnectionFactory.getConnection();
        PreparedStatement pre = null;
        ResultSet res = null;
        Person newPerson = null;
        try {
            pre=connection.prepareStatement(sql);
            res=pre.executeQuery();

            while (res.next()){
                newPerson = new Person();
                newPerson.setUserPassword(res.getString("userPassword"));
                newPerson.setUserAccount(res.getString("userAccount"));
                newPerson.setUserBirthday(res.getString("userBirthday"));
                newPerson.setUserAge(res.getInt("userAge"));
                newPerson.setUserPos(res.getString("userPos"));
                newPerson.setUserSex(res.getString("userSex"));
                newPerson.setUserDepart(res.getString("userDepart"));
                newPerson.setUserIdentity(res.getString("userIdentity"));
                newPerson.setUserName(res.getString("userName"));

            }
        } catch (SQLException throwables){
            throwables.printStackTrace();
        }

        return newPerson;
    }
}
